import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class CountDisplayServlet extends HttpServlet {
    public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException{
        //取出ServletContext中存的次数
        ServletContext context=this.getServletContext();
        Object obj= context.getAttribute("data");
        int count=(int)obj;
        response.setContentType("text/html;charset=UTF-8");
        response.getWriter().println("<h1>网站被访问了"+count+"次！</h1>");
    }
    public void doPost(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException{
        doGet(request,response);
    }
}
